package com.caocaog.market.data.transfer.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.caocaog.market.data.transfer.entity.MkSiteArea;
import com.caocaog.market.data.transfer.entity.SiteAreaSimple;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * @author liguang
 * @version 1.0.0
 * @Project jeecg-boot
 * @Package com.caocaog.market.data.transfer.mapper.xml
 * @ClassName MkSiteAreaBasicMapper.java
 * @createTime 2021年11月16日 09:40:00
 * @Description TODO
 */
@Mapper
public interface MkSiteAreaMapper {
    /**
     * 查询mysql库中所有分站（代理商）区域信息
     * 分页查询
     * @return
     * */
    public IPage<MkSiteArea> findAllSiteAreaByNow(Page<MkSiteArea> page,MkSiteArea mkSiteArea);
    /**
     * 查询mysql库中所有分站（代理商）区域信息
     * 不分页
     * @return
     * */
    public List<MkSiteArea> findAllSiteAreaByNow(@Param("mkSiteArea") MkSiteArea mkSiteArea);

    /**
     * 查询mysql库中所有分站（代理商）区域信息的总记录数
     * @return int
     */
    public int countForfindAllSiteAreaByNow(@Param("mkSiteArea") MkSiteArea mkSiteArea);

    /**
     * 根据siteId查询该分站下有多少条区域信息
     * @Return int
     */
    public int countForSiteAreaBySiteId(String siteId);


    /**
     * 查询mysql库中所有分站（代理商）区域信息记录数
     * 该方法查询到的记录数应该和findAllSiteAreaByNow查询到的记录数是一样的
     * @return
     * */
    public int deleteSiteAreaBySiteId(Map<String,String> paramMap );

    /**
     * 插入数据
     */
    public int insertSiteAreaForInsert(MkSiteArea mkSiteArea);

    @Select("SELECT msa.site_id, msa.province_center, msa.city_center, msa.district_center, msa.town_center, msb.site_type AS `siteName` FROM mk_site_area AS msa LEFT JOIN mk_site_basic AS msb ON(msa.site_id = msb.id) WHERE msb.del_flag = 0 AND msa.del_flag = 1")
    List<MkSiteArea> selectSiteAreaList();

    @Select("SELECT * FROM mk_site_area WHERE del_flag = 1 AND district_adcode = #{districtAdCode}")
    List<MkSiteArea> getSiteAreaByDistrictAdCode(@Param("districtAdCode") String districtAdCode);

    @Select("SELECT * FROM mk_site_area WHERE site_id=#{defSiteCode}")
    List<MkSiteArea> getDefaultSite(String defSiteCode);

}
